package com.flex.core.validate.impl;

import com.flex.core.validate.AbstractValidator;

/**
 * 数字验证器，验证数字的大小
 * 
 * @author radio
 * 
 */
public class IntValidator extends AbstractValidator {

	/**
	 * 将属性值转换成整数，与验证器注解中的min和max进行大小比较
	 */
	protected String doValidate() {
		String msg = "";
		Object value = getFiledValue();
		if (value instanceof Integer) {
			int max = Integer.valueOf(getValidation().max());
			int min = Integer.valueOf(getValidation().min());
			Integer valueInt = (Integer) value;
			if (valueInt.intValue() < min || valueInt.intValue() > max) {
				msg = getValidation().message();
			}
		}
		if (value instanceof Long) {
			long max = Long.valueOf(getValidation().max());
			long min = Long.valueOf(getValidation().min());
			Long valueLong = (Long) value;
			if (valueLong.longValue() < min || valueLong.longValue() > max) {
				msg = getValidation().message();
			}
		}
		return msg;
	}

}
